#!/usr/bin/env bash
set -euo pipefail

IMAGE_NAME="document-to-html"
IMAGE_TAG="${1:-20251016}"
REMOTE_USER="maintainer"
REMOTE_HOST="10.11.3.68"
REMOTE_PORT="22"
REMOTE_DIR="/data01/llm/document-to-html"
ARCHIVE_NAME="${IMAGE_NAME}.tar"
COMPOSE_FILE="docker-compose.yml"
REMOTE_TARGET="${REMOTE_USER}@${REMOTE_HOST}"

docker buildx build --platform linux/amd64 -t "${IMAGE_NAME}:${IMAGE_TAG}" .

docker save -o "${ARCHIVE_NAME}" "${IMAGE_NAME}:${IMAGE_TAG}"

scp -P "${REMOTE_PORT}" "${ARCHIVE_NAME}" "${COMPOSE_FILE}" "${REMOTE_TARGET}:${REMOTE_DIR}/"

ssh -p "${REMOTE_PORT}" "${REMOTE_TARGET}" <<EOF
set -euo pipefail
cd "${REMOTE_DIR}"
docker load -i "${REMOTE_DIR}/${ARCHIVE_NAME}"
docker-compose down
docker-compose up -d
EOF

# cbbg@2025#AI